package fr.gdi.android.news;

import java.util.List;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import fr.gdi.android.news.ShareReceiverProxyAdapter.ShareReceiverProxy;
import fr.gdi.android.news.utils.Constants.Preferences;
import fr.gdi.android.news.utils.PreferenceUtils;

public class HideShareActivity extends ListActivity
{
    private ShareReceiverProxyAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hide_activities);
        List<ShareReceiverProxy> proxies = PreferenceUtils.getShareActivities(this); 
        
        adapter = new ShareReceiverProxyAdapter(this, proxies);
        adapter.setShowCheckbox(true);
        setListAdapter(adapter);
        
        final Activity ctx = this;
        final StringBuilder b = new StringBuilder();
        Button button = (Button) findViewById(R.id.save);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0)
            {
                for (int u = 0, l = adapter.getCount(); u < l; u++)
                {
                    if ( adapter.getItem(u).isDisabled() )
                    {
                        ShareReceiverProxy proxy = adapter.getItem(u);
                        String act = proxy.receiverPackage + proxy.receiverName;
                        if ( u > 0 ) b.append(";");
                        b.append(act);
                    }
                }
                PreferenceUtils.setStringPreference(ctx, Preferences.DISABLED_SHARE_ACTIVITIES, b.toString());
                ctx.finish();
            }
        });
        
        button = (Button) findViewById(R.id.cancel);
        button.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View arg0)
            {
                ctx.finish();
            }
        });
        
        /*
        CheckBox cb = (CheckBox) findViewById(R.id.SHARE_INCLUDE_THUMBNAILS);
        cb.setChecked(PreferenceUtils.getBooleanPreference(this, Preferences.SHARE_INCLUDE_THUMBNAILS));
        cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton cb, boolean checked)
            {
                PreferenceUtils.setBooleanPreference(HideShareActivity.this, Preferences.SHARE_INCLUDE_THUMBNAILS, checked);
            }
        });
        */
    }
}
